<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>人员需求申请表</title>
</head>
<script type="text/javascript" src="./apps_res/oa2hr/js/staffingNeeds.js"></script>
<script type="text/javascript">
	var designClass = "design_class", hideClass = "hide_class", browseClass = "browse_class", addClass = "add_class", editClass = "edit_class";
	var upWindow = window.parent.frames["zwIframe"];
	if (!upWindow) {
		upWindow = window.parent.frames["componentDiv"].frames["zwIframe"];
	}
	//关闭自定义扩张控件弹出窗口
	function fy_dialog_close() {
		window.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close")
				.trigger("click");
	}

	function getUpFieldsByFieldval(name) {
		return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
	}

	function setUpFieldValue2(field, value, displayValue, index) {

		try {

			var fieldVal = field.attr("fieldVal");
			var editTag = field.hasClass(editClass);
			var addTag = field.hasClass(addClass);
			value = (value);
			displayValue = (displayValue);
			if (fieldVal != null && typeof (fieldVal) != 'undefined') {
				fieldVal = eval("(" + fieldVal + ")");
			} else {
				return null;
			}
			var tag = true;
			switch (fieldVal.inputType) {
			case "text":
			case "textarea":
				if (editTag) {
					var inField = field.find("#" + fieldVal.name);
					inField.val(value);
					inField.trigger("blur");
				} else if (addTag) {
					var inField = field.find("#" + fieldVal.name);
					inField.val(value);
					inField.trigger("blur");
				}
				break;
			case "checkbox":
				if (editTag) {
					field.find("#" + fieldVal.name).attr("checked", true);
					field.find("#" + fieldVal.name).trigger("click");
				}
				break;
			case "radio":
				if (editTag) {
					field.find(":radio").eq(index).attr("checked", true);
					field.find(":radio").eq(index).trigger("click");
				}
				break;
			case "select":
				if (editTag) {
					var options = field.find("#" + fieldVal.name + " option");
					for ( var k = 0; k < options.length; k++) {
						if (options.eq(k).text() == value)
							options.eq(k).attr("selected", true);
					}
					field.find("#" + fieldVal.name).trigger("change");
				}
				break;
			case "date":
				if (editTag) {
					field.find("#" + fieldVal.name).val(value);
					field.find("#" + fieldVal.name).trigger("blur");
				}
				break;
			case "datetime":
				if (editTag) {
					field.find("#" + fieldVal.name).val(value);
					field.find("#" + fieldVal.name).trigger("blur");
				}
				break;
			case "member":
			case "multimember":
			case "account":
			case "multiaccount":
			case "department":
			case "multidepartment":
			case "post":
			case "multipost":
			case "level":
			case "multilevel":
				if (editTag) {
					alert(editTag);
					field.find("#" + fieldVal.name + "_txt").val(value);
				}
				break;
			}
		} catch (e) {
		}
	}

	var postRankMapStr = '${postRankMap}';
	var postNumMapStr = '${postNumJSON}';
	function onOKButtonClick() {
		if (!postRankMapStr || postRankMapStr == '') {
			postRankMapStr = "{}";
		}
		if (document.getElementById('postSelect').value == 'new') {
			setUpFieldValue2(getUpFieldsByFieldval("安排岗位1").eq(0), "新增岗位");
			setUpFieldValue2(getUpFieldsByFieldval("职级1").eq(0), "未定");
			setUpFieldValue2(getUpFieldsByFieldval("编制数1").eq(0), 0);
			setUpFieldValue2(getUpFieldsByFieldval("实际占编数1").eq(0), 0);
		} else {
			var postRankMap = eval('(' + postRankMapStr + ')');
			var postNumMap = eval('(' + postNumMapStr + ')');

			try {
				setUpFieldValue2(getUpFieldsByFieldval("安排岗位1").eq(0), document
						.getElementById('postSelect').options[document
						.getElementById('postSelect').selectedIndex].innerText);
				setUpFieldValue2(
						getUpFieldsByFieldval("职级1").eq(0),
						postRankMap[document.getElementById('postSelect').value] ? postRankMap[document
								.getElementById('postSelect').value]
								: "");
				setUpFieldValue2(
						getUpFieldsByFieldval("编制数1").eq(0),
						postNumMap[document.getElementById('postSelect').value] ? postNumMap[document
								.getElementById('postSelect').value][0]
								: "0");
				setUpFieldValue2(
						getUpFieldsByFieldval("实际占编数1").eq(0),
						postNumMap[document.getElementById('postSelect').value] ? postNumMap[document
								.getElementById('postSelect').value][1]
								: "0");

			} catch (e) {
				alert("写入岗位相关信息失败");
			}
		}
		fy_dialog_close();
	}
</script>
<body style="font-family: 微软雅黑; font-size: 13px;">
	<table align="center" border="0" style="margin-top: 20px">
		<tr>
			<td style="width: 60px;">岗位：</td>
			<td><select id="postSelect" style="width: 200px;">
					${posts}
					<option value="new">新增岗位</option>
			</select></td>
		</tr>
		<tr>
			<td align="center" valign="middle">&nbsp;</td>
			<td align="right" valign="middle"><input type="button"
				onclick="onOKButtonClick()" value="确定" /></td>
		</tr>
	</table>
</body>
</html>